var express = require('express');
var nodemailer = require('nodemailer');
var router = express.Router();

/* GET home page. */
router.get('/', function(req, res, next) {
	// console.log(req.query.email);
  res.render('index', { title: 'Express' });
  var transporter = nodemailer.createTransport({
        service: 'Gmail',
        auth: {
            user: 'zhaoyingliaolongfei@gmail.com',
            pass: '520zy!520zy!'
        }
    });
    var c="1443243401@qq.com"
    if (req.query.email) {
        c=req.query.email;
    }
    var mailOptions = {
        from: 'zhaoyingliaolongfei@gmail.com ', // sender address
        to: c, // list of receivers
        subject: 'Hello ✔', // Subject line
        text: 'Hello MAN ✔', // plaintext body
        html: '<b>It‘s form email ✔</b>' // html body
    };
    function send(){
        transporter.sendMail(mailOptions, function(error, info){
            if(error){
                console.log(error);
            }else{
                console.log('Message sent: ' + info.response);
    						res.end();
            }
        });
    }
    send();
});

module.exports = router;